﻿using InvoiceInvoker.Logic.Repositories;
using NUnit.Framework;

namespace InvoiceInvoker.Logic.Tests.RepositoriesTests
{
	[TestFixture]
	public class RegisteredSellerRepositoryTests
	{
		RegisteredSellerRepository repository;
		int initialSellersNumber;

		[SetUp]
		public void TestsSetup()
		{
			repository = new RegisteredSellerRepository();
			initialSellersNumber = repository.GetRegisteredSellersNumber();
		}

		[Test]
		public void GetsById()
		{
			RegisteredSeller result = repository.GetById(1);

			Assert.AreEqual("BankAccountNumber", result.BankAccountNumber);
			Assert.AreEqual("BankName", result.BankName);
			Assert.AreEqual("BankSwift", result.BankSwift);
			Assert.AreEqual("City", result.City);
			Assert.AreEqual("CompanyName", result.CompanyName);
			Assert.AreEqual("FirstName", result.FirstName);
			Assert.AreEqual(1, result.Id);
			Assert.AreEqual("InvoiceNumberFormat", result.InvoiceNumberFormat);
			Assert.AreEqual("LastInvoiceNumber", result.LastInvoiceNumber);
			Assert.AreEqual("LastName", result.LastName);
			Assert.AreEqual("NIP", result.Nip);
			Assert.AreEqual("PostalCode", result.PostalCode);
			Assert.AreEqual("REGON", result.Regon);
			Assert.AreEqual("Street", result.Street);
			Assert.AreEqual("UserName", result.UserName);
		}

		[Test]
		public void Adds()
		{
			RegisteredSeller seller = new RegisteredSeller();
			seller.BankAccountNumber = "0000-0000-0000-0000-0000";
			seller.BankName = "TestBank";
			seller.BankSwift = "TB";
			seller.City = "TestCity";
			seller.CompanyName = "TestCompany Inc.";
			seller.FirstName = "TestName";
			seller.InvoiceNumberFormat = "NN/MM/YY";
			seller.LastInvoiceNumber = "00/08/10";
			seller.LastName = "TestSurname";
			seller.Nip = "0000000000";
			seller.PostalCode = "15-281";
			seller.Regon = "0000000000000";
			seller.Street = "TestStreet";
			seller.UserName = "TestUserName";

			repository.Add(seller);

			Assert.AreEqual(initialSellersNumber + 1, repository.GetRegisteredSellersNumber());
		}

		[Test]
		public void Removes()
		{
			RegisteredSeller seller = new RegisteredSeller();
			seller.BankAccountNumber = "toRemove";
			seller.BankName = "toRemove";
			seller.BankSwift = "toRemove";
			seller.City = "toRemove";
			seller.CompanyName = "toRemove";
			seller.FirstName = "toRemove";
			seller.InvoiceNumberFormat = "toRemove";
			seller.LastInvoiceNumber = "toRemove";
			seller.LastName = "toRemove";
			seller.Nip = "toRemove";
			seller.PostalCode = "toRemove";
			seller.Regon = "toRemove";
			seller.Street = "toRemove";
			seller.UserName = "to Remove";

			repository.Add(seller);
			Assert.AreEqual(initialSellersNumber + 1, repository.GetRegisteredSellersNumber());

			repository.Remove(seller.Id);
			Assert.AreEqual(initialSellersNumber, repository.GetRegisteredSellersNumber());
		}

		[Test]
		public void Updates()
		{
			int toTestId = 2;

			RegisteredSeller toTest = repository.GetById(toTestId);
			string newName = (toTest.FirstName.Length < 20) ? (toTest.FirstName + ".") : ".";

			RegisteredSeller seller = new RegisteredSeller();
			seller.Id = toTestId;
			seller.FirstName = newName;
			seller.BankAccountNumber = "test";
			seller.BankName = "test";
			seller.BankSwift = "test";
			seller.City = "test";
			seller.CompanyName = "test";
			seller.InvoiceNumberFormat = "test";
			seller.LastInvoiceNumber = "test";
			seller.LastName = "test";
			seller.Nip = "test";
			seller.PostalCode = "test";
			seller.Regon = "test";
			seller.Street = "test";
			seller.UserName = "test";

			repository.Update(seller);
			RegisteredSeller result = repository.GetById(toTestId);

			Assert.AreEqual(newName, result.FirstName);
			Assert.AreEqual(initialSellersNumber, repository.GetRegisteredSellersNumber());
		}
	}
}
